package io.github.hadyang.leetcode.offer;

import org.junit.Test;

/** @author haoyang.shi */
public class Fibonacci {

  @Test
  public void test() {
    System.out.println(Fibonacci(2));
    System.out.println(Fibonacci(3));
    System.out.println(Fibonacci(4));
    System.out.println(Fibonacci(5));
    System.out.println(Fibonacci(39));
  }

  public int Fibonacci(int n) {
    if (n == 0) {
      return 0;
    }

    if (n == 1) {
      return 1;
    }

    int l = 1, ll = 0;

    for (int i = 2; i <= n; i++) {
      int t = ll + l;
      ll = l;
      l = t;
    }

    return l;
  }
}
